﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Vds2465Telegrams;

namespace Vds2465Parser
{
	internal static class GenParse_UserData_54_AsciiCharacters
	{
		#region internal methods

		internal static byte[] GenerateBytes(UserData userData)
		{
			if (userData is UserData_54_AsciiCharacters)
			{
				UserData_54_AsciiCharacters userData54 = userData as UserData_54_AsciiCharacters;
				return GenParse_UserData_AsciiBytes.GenerateBytes(UserData.UserData54AsciiChars, userData54.GetCopyOfAsciiBytes(), UserData_54_AsciiCharacters.MaxNrOfChars);
			}

			// TODO handle error - wrong UserData type
			byte[] userDataBytes = null;

			return userDataBytes;
		}

		internal static bool ParseBytes(byte[] userDataBytes, out UserData userData54AsciiCharacters, out int consumedBytes)
		{
			userData54AsciiCharacters = null;
			consumedBytes = 0;
			byte[] asciiCharacterBytes;

			bool bRetVal = GenParse_UserData_AsciiBytes.ParseBytes(userDataBytes, UserData.UserData54AsciiChars, out asciiCharacterBytes, out consumedBytes);
			if (bRetVal)
			{
				userData54AsciiCharacters = new UserData_54_AsciiCharacters(asciiCharacterBytes);
			}

			return bRetVal;
		}

		#endregion internal methods
	}
}
